package com.szjlc.mybatis.sqlinterceptor.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.szjlc.mybatis.sqlinterceptor.entity.Customer;
import com.szjlc.mybatis.sqlinterceptor.mapper.CustomerMapper;
import com.szjlc.mybatis.sqlinterceptor.service.CustomerService;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 客户表(Customer)表服务实现类
 * @author makejava
 * @since 2022-11-28 23:30:10
 */
@Slf4j
@Service("customerService")
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer>
        implements CustomerService {
    @Resource
    private CustomerMapper customerMapper;

    /**
     * 通过ID查询单条数据
     * @param customerId 主键
     * @return 实例对象
     */
    @Override
    public Customer findById(Integer customerId) {
        long start = System.currentTimeMillis();
        Customer customer = this.customerMapper.findById(customerId);
        log.info("execute time={}ms", System.currentTimeMillis() - start);
        return customer;
    }

    /**
     * 查询多条数据
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Customer> queryAllByLimit(int offset, int limit) {
        return this.customerMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 查询所有
     * @return 对象列表
     */
    @Override
    public List<Customer> findAll() {
        long start = System.currentTimeMillis();
        List<Customer> list = this.customerMapper.findAll();
        log.info("execute time={}ms", System.currentTimeMillis() - start);
        return list;
    }

    /**
     * 新增数据
     * @param customer 实例对象
     * @return 实例对象
     */
    /* @Override
    public Customer save(Customer customer) {
        this.customerMapper.insert(customer);
        return customer;
    } */

    /**
     * 修改数据
     * @param customer 实例对象
     * @return 实例对象
     */
    @Override
    public Customer update(Customer customer) {
        this.customerMapper.update(customer);
        return this.findById(customer.getCustomerId());
    }

    /**
     * 通过主键删除数据
     * @param customerId 主键
     */
    @Override
    public void deleteById(Integer customerId) {
        this.customerMapper.deleteById(customerId);
    }

}
